package com.xuerhua.yxt.controller.sys.student;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xuerhua.yxt.common.RspResult;
import com.xuerhua.yxt.common.enums.Status;
import com.xuerhua.yxt.controller.BaseController;
import com.xuerhua.yxt.model.Grid;
import com.xuerhua.yxt.model.StudentInfo;
import com.xuerhua.yxt.page.Page;
import com.xuerhua.yxt.reqVo.StudentReqVO;
import com.xuerhua.yxt.service.IStudentService;
import com.xuerhua.yxt.utils.BeanUtils;
import com.xuerhua.yxt.view.StudentInfoView;

@RequestMapping("sys/student/outinput")
@Controller
public class SysStudentOutinputController extends BaseController {
	
	@Autowired
	private IStudentService studentService;
	
	@RequestMapping(value={"","/"})
	public String Index() {
		return "sys/student/outinput";
	}
	
	@RequestMapping("pageQuery")
	@ResponseBody Object pageQuery(StudentReqVO vo){
		try {
			Page<StudentInfo> page = new Page<>();
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			page.setParams(vo);
			List<StudentInfo> list = studentService.selectFullListByPage(page);
			Grid grid = new Grid();
			grid.setRows(BeanUtils.copyAs(list, StudentInfoView.class));
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@RequestMapping("zrzc")
	@ResponseBody Object addUpdate(StudentReqVO vo) {
		try {
			Integer id = vo.getStudentId();
			Integer type = vo.getStatus();
			StudentInfo studentInfo = new StudentInfo();
			studentInfo.setId(id);
			studentInfo.setSchoolId(vo.getSchoolId());
			if(type==0) {
				studentInfo.setStatus(1);
				studentInfo.setOutTermId(0);
				studentInfo.setEnterTermId(getCurrentTerm().getId());
			}else {
				studentInfo.setOutTermId(getCurrentTerm().getId());
				studentInfo.setEnterTermId(0);
				studentInfo.setStatus(0);
			}
			studentService.updateById(studentInfo);
			return new RspResult(Status.SUCCESS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return new RspResult(Status.FAIL);
	}
	
}
